package com.sairui.xiaoruilibdemo;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * Created by sunqiyong on 2017/3/31.
 */
public class MyViewPager extends ViewPager {
    private boolean mGestureScrollble = false;// 是否支持手势滑动

    /**
     * @param context
     * @param attrs
     */
    public MyViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent arg0) {
        if (!mGestureScrollble) {
            // 不拦截触摸事件
            return false;
        } else {
            return super.onInterceptTouchEvent(arg0);
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (!mGestureScrollble) {
            // 不触发触摸事件
            return false;
        }
        return super.onTouchEvent(ev);
    }

    /**
     * 获取是否支持滑动
     *
     * @return
     */
    public boolean isGestureScrollble() {
        return mGestureScrollble;
    }

    /**
     * 设置是否支持滑动
     *
     * @param scrollble
     */
    public void setGestureScrollble(boolean scrollble) {
        this.mGestureScrollble = scrollble;
    }
}
